In [1]:
import numpy as np
In [22]:
X = np.array([[0,0,1],
[0,1,1],
[1,0,1],
[1,1,1]])
Y = np.array([[0],
[1],
[1],
[0]])
In [23]:
X
Out[23]:
In [24]:
Y
Out[24]:
In [12]:
num_epochs = 60000
#initialize weights
syn0 = 2*np.random.random((3,4)) - 1
syn1 = 2*np.random.random((4,1)) - 1
syn0
Out[12]:
In [13]:
syn1
Out[13]:
In [15]:
def nonlin(x,deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))
In [33]:
for epoch in range(num_epochs):
#feed forward through layers 1, 2 & 3
l0 = X # the input layer
l1 = nonlin(np.dot(l0, syn0)) # hidden layer
l2 = nonlin(np.dot(l1, syn1)) # final, hence output layer
# by how much did we miss the target value?
l2_error = Y - l2
l2_delta = l2_error * nonlin(l2, deriv=True)
# propgating to the next layer
l1_error = np.dot(l2_delta, syn1.T)
l1_delta = l1_error * nonlin(l1, deriv=True)
# updating weights
syn1 += l1.T.dot(l2_delta)
syn0 += l0.T.dot(l1_delta)
if (epoch% 10000) == 0:
print("Error:", (np.mean(np.abs(l2_error))))
#print(l1_error)
print('============')
The challenge for this video is to build a neural network to predict the magnitude of an Earthquake given the date, time, Latitude, and Longitude as features. This is the dataset. Optimize at least 1 hyperparameter using Random Search. See this example for more information.
You can use any library you like, bonus points are given if you do this using only numpy.
In [ ]: